if (!app.user) {app.redirect('/admin/login.php')}
jQuery(function() {

	var grid = $('#product-grid li:first').clone();

	function getProductList() {
		var serverReturn = _get('/app/index.php?d=admin&c=product&m=get_product_list');
		return serverReturn.product_list;
	}

	function generateProductGrid(product) {
		var gridClone = grid.clone();
		gridClone.find('div > img').attr('src', '/app/'+product['product_high_discount_picture']);
		gridClone.find('div > div > h3').html(product['product_name']);  // 产品名称
		gridClone.find('[name="product_vote_count"]').html(product['product_vote_count']);  // 投票数量
		gridClone.find('[name="product_share_count"]').html(product['product_share_count']);  // 分享数量
		gridClone.find('a.btn[name="edit"]').attr('href', 'product_edit.php#'+product['product_id']);
		if (product['state'] == 'end_sell') {
			gridClone.find('a.btn[name="edit"]').addClass('disabled').removeAttr('href');
		}
		return gridClone;
	}

	function updateProductGrid() {
		$('#product-grid').empty();
		var products = getProductList();
		// console.log(products);
		for (var i in products) {
			$('#product-grid').append( generateProductGrid( products[i] ) );
		}
	}

	updateProductGrid();
})